package com.lizhk;
import java.sql.*;
public class Connect {

	/**
	 * @param args
	 */
	public String url="jdbc:mysql://localhost:3306/tpms_f?user=root&password=lizhk&useUnicode=true&characterEncoding=UTF-8";
    public Connection conn;
    public Statement stmt;
	public Connect()
	{
		
	}
	
	public  ResultSet exeQuery(String str){
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			
			try {
				conn = DriverManager.getConnection(url);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			try {
				stmt = conn.createStatement();
				ResultSet rs= stmt.executeQuery(str);
				return rs;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	//request.setCharacterEncoding("gb2312");
	    //url="jdbc:mysql://localhost:3306/tpms_f?user=root&password=lizhk" ;
		
	return null;

	}
	
	public  boolean exe(String str){
		try {
		Class.forName("com.mysql.jdbc.Driver");
    	//request.setCharacterEncoding("gb2312");
	    //url="jdbc:mysql://localhost:3306/tpms_f?user=root&password=lizhk" ;
		conn = DriverManager.getConnection(url);
		stmt = conn.createStatement();
		boolean rs= stmt.execute(str);
		return rs;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
		}

	}
	
	public  int exeUpdate(String str){
		try {
		Class.forName("com.mysql.jdbc.Driver");
    	//request.setCharacterEncoding("gb2312");
	    //url="jdbc:mysql://localhost:3306/tpms_f?user=root&password=lizhk" ;
		conn = DriverManager.getConnection(url);
		stmt = conn.createStatement();
		int rs= stmt.executeUpdate(str);
		return rs;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return -1;
		}

	}
	
	public void stateClose(){
		try {
			conn.close();
		    stmt.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public String codeToString(String str) 
	{
	  String s=str; 
	  try 
	    { 
	    byte tempB[]=s.getBytes("ISO-8859-1"); 
	    s=new String(tempB); 
	    return s; 
	  } 
	  catch(Exception e) 
	  { 
	    return s; 
	  }  
	} 

}
